{% load static %}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="shortcut icon" type="image/png" href="{% static 'games/favicon.png' %}"/>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="{% static 'games/main.css' %}">

    <title>Games Chat</title>
</head>
<body>
    <header class="site-header">
      <nav class="navbar navbar-expand-md navbar-dark bg-steel fixed-top">
        <div class="container">
          <a class="navbar-brand mr-4" href="{% url 'games' %}">Games Chat</a>
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggle" aria-controls="navbarToggle" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
          </button>
          <div class="collapse navbar-collapse" id="navbarToggle">
            <div class="navbar-nav mr-auto">
              <a class="nav-item nav-link" href="{% url 'games' %}">Games</a>
              {% if user.is_authenticated %}
                <a class="nav-item nav-link" href="{% url 'game-create' %}">Add Game</a>
              {% endif %}
            </div>
            <div class="navbar-nav">
              {% if user.is_authenticated %}
                <a class="nav-item nav-link" href="{% url 'profile' %}">
                  <img src="{{ user.profile.image_url }}" class="rounded-circle small-profile-image" alt="profile-image" />
                </a>
                <div class="dropdown">
                  <a class="nav-item nav-link font-weight-bold dropdown-toggle" 
                    href="#" 
                    role="button" 
                    id="dropdownMenuLink" 
                    data-toggle="dropdown" 
                    aria-haspopup="true" 
                    aria-expanded="false">
                    <span class="badge badge-danger" id="notifier-badge"></span>
                    {{ user.username }}
                  </a>

                  <div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
                    <a class="dropdown-item" href="{% url 'profile' %}">Profile</a>
                    <a class="dropdown-item" href="{% url 'inbox' %}">
                      <span class="badge badge-danger" id="notifier-badge"></span> Inbox
                    </a>
                    <a class="dropdown-item" href="{% url 'chat' %}">Create chat</a>
                  </div>
                </div>
                <a class="nav-item nav-link" href="{% url 'logout' %}">Logout</a>
              {% else %}
                <a class="nav-item nav-link" href="{% url 'login' %}">Login</a>
                <a class="nav-item nav-link" href="{% url 'register' %}">Register</a>
              {% endif %}
            </div>
          </div>
        </div>
      </nav>
    </header>

    <main class="container">
      <div class="row">
        {% if not user.is_authenticated %}
          <div class="alert mx-auto alert-warning">
            You are not logged in and some features may not be available!
            <a href="{% url 'login' %}">Login</a>
          </div>
        {% endif %}
      </div>
      {% if messages %}
        {% for message in messages %}
          <div class="row">
            <div class="alert mx-auto alert-{{ message.tags }}">
              {{ message }}
            </div>
          </div>
        {% endfor %}
      {% endif %}
      {% block content %}{% endblock content %}
    </main>

    <div class="container">
      <footer class="pt-4 my-md-5 pt-md-5 border-top">
        <div class="row">
          <div class="col-md-4">
            <img class="mb-2" src="{% static 'games/favicon.png' %}" alt="TalkJS" width="40" height="40">
            <small class="d-block text-muted">© 2019-2020</small>
            <small>Example created for 
              <a target="_blank" href="https://talkjs.com">TalkJS</a> by 
              <a target="_blank" href="https://github.com/mdyakov">Dimitar Dyakov</a>.
            </small>
          </div>
          <div class="col-md-2">
            <h5>Resources</h5>
            <ul class="list-unstyled text-small">
              <li><a class="text-muted" target="_blank" href="https://talkjs.com/tutorials/">Tutorials</a></li>
              <li><a class="text-muted" target="_blank" href="https://github.com/talkjs/talkjs-examples">Examples</a></li>
              <li><a class="text-muted" target="_blank" href="https://demo.talkjs.com/">Demo</a></li>
            </ul>
          </div>
          <div class="col-md-4">
            <h5>Support</h5>
            <ul class="list-unstyled text-small">
              <li><a class="text-muted" target="_blank" href="https://talkjs.com/?chat">Chat with TalkJS</a></li>
              <li><a class="text-muted" target="_blank" href="mailto:hey@talkjs.com">Email TalkJS</a></li>
              <li><a class="text-muted" target="_blank" href="https://talkjs.com/docs/">Documentation</a></li>
            </ul>
          </div>
          <div class="col-md-2">
            <a href="#">Back to top</a>
          </div>
      </footer>
    </div>

    <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

    {% if user.is_authenticated %}
      <script>
        (function(t,a,l,k,j,s){
        s=a.createElement('script');s.async=1;s.src="https://cdn.talkjs.com/talk.js";a.head.appendChild(s)
        ;k=t.Promise;t.Talk={v:3,ready:{then:function(f){if(k)return new k(function(r,e){l.push([f,r,e])});l
        .push([f])},catch:function(){return k&&new k()},c:l}};})(window,document,[]);
      </script>
      <script src="{% static 'games/js/main.js' %}"></script>

      {% block extrajs %}{% endblock extrajs %}
    {% else %}
      <script>sessionStorage.removeItem('currentSession')</script>
    {% endif %}
</body>
</html>